import java.util.Arrays;

public class Solution2241 {

    long[] res=new long[5];
    int[] size=new int[]{20,50,100,200,500};

    public Solution2241() {

    }

    public void deposit(int[] banknotesCount) {
        for (int i=0;i<5;i++){
            res[i]+=banknotesCount[i];
        }
    }

    public int[] withdraw(int amount) {
        long[] restore= Arrays.copyOf(res,5);
        int[] ans=new int[5];
        for (int i=4;i>=0;i--){
            int m=(int)(Math.min(res[i],amount/size[i]));
            ans[i]=m;
            res[i]-=m;
            amount-=size[i]*m;
        }
        if (amount!=0){
            res=restore;
            return new int[]{-1};
        }else{
            return ans;
        }
    }

    public static void main(String[] args) {
        Solution2241 solution2241=new Solution2241();
        solution2241.deposit(new int[]{0,0,1,2,1});
        System.out.println(Arrays.toString(solution2241.withdraw(600)));
        solution2241.deposit(new int[]{0,1,0,1,1});
        System.out.println(Arrays.toString(solution2241.withdraw(600)));
        System.out.println(Arrays.toString(solution2241.withdraw(550)));
    }
}
